package com.bingo.controller;


import com.bingo.common.R;
import com.bingo.entity.HisPool;
import com.bingo.entity.dto.req.ReqClearLoss;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.service.ClearLossService;
import com.bingo.service.HisPoolService;
import com.bingo.until.IsToday;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * @description 清塘损耗的控制类
 * @author Bingo
*/
@RestController
@RequestMapping("/clearLoss")
public class ClearLossController {

    private ClearLossService clearLossService;
    @Autowired
    public void setClearLossService(ClearLossService clearLossService) {
        this.clearLossService = clearLossService;
    }

    private HisPoolService hisPoolService;
    @Autowired
    public void setHisPoolService(HisPoolService hisPoolService) {
        this.hisPoolService = hisPoolService;
    }

    @PostMapping("/report")
    public R clearLoss(@RequestBody ReqClearLoss reqClearLoss) {
        if (!IsToday.isToday(reqClearLoss.getDate())){
            HisPool pool = hisPoolService.getPoolByNo(reqClearLoss.getPoolNo());
            if (pool == null || pool.getType() == 0){
                return R.error("不存在该分出池塘或为空塘!");
            }
        }
        return clearLossService.add(reqClearLoss.getPoolNo(),reqClearLoss.getDate(), reqClearLoss.getUserId());
    }

    @PostMapping
    public R selectEveryDayClearLoss(@RequestBody ReqForm reqForm) {
        return R.success(clearLossService.selectEveryDayClearLoss(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1]));
    }

    @PostMapping("/record")
    public R feedLossRecord(@RequestBody ReqForm reqForm) {
        return R.success(clearLossService.selectClearRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1],reqForm.getUserId()));
    }

    @PostMapping("/site")
    public R siteClearLoss(@RequestBody ReqForm reqForm) {
        return R.success(clearLossService.selectSiteClearLoss(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1]));
    }

}
